package asia.hymsk.spring.utils;

import cn.hutool.crypto.digest.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * @author 花于陌上开
 */
@Component
public class CryptoUtils {
    static String salt;
    static int index;
    static int count;

    protected CryptoUtils(@Autowired CryptoProperties cryptoProperties) {
        CryptoUtils.salt = cryptoProperties.getSalt();
        CryptoUtils.index = cryptoProperties.getIndex();
        CryptoUtils.count = cryptoProperties.getCount();
    }

    public static String encrypted(String str) {
        return new MD5(salt.getBytes(StandardCharsets.UTF_8), index, count).digestHex(str);
    }

}
